package edu.qd.learn.newchapter.chapter04;

import java.nio.charset.Charset;

/**
 * string原生类
 *
 * @author 布衣
 */
public class StringLearn {

    public static final String s1 = "tt";

    public static void main(String[] args) {


        String t1 = "a" + "b" + "c";
        String t2 = "ab" + "c";
        System.out.println(t1 == t2);
        String s = "a";
        String t3 = s + "bc";
        // String t3 =  new StringBuilder(s).append("bc").toString();

        //jdk1.5 字符串 + 会产生大量的不用的临时变量
        //new StringBuilder(s).append("bc");


        System.out.println(t3 == t1);
        String t4 = s + "b" + "c";
        System.out.println((t4 == t1) +"==>");

        String str = "abc";
        String str0 = "abc";
        System.out.println(t1 == str);
        // == 在基本类型判断值 是否相同 ，，，在引用类型当中判断 地址是否相同
        System.out.println(str == str0);
        System.out.println(str.equals(str0));


        String str1 = new String("abc");
        System.out.println(str == str1);

        String str2 = new String(new char[]{'a', 'b', 'c'});
        System.out.println(str2 == str1);

        String str3 = new String(new char[]{'a', 'b', 'c'}, 0, 3);

        String ing = "abc";
        String ing1 = ing.intern();
        System.out.println(ing == ing1);

        String ing2 = new String("def");
        String ing3 = ing2.intern();
        String ing4 = ing2.intern();
        System.out.println(ing4 == ing3);

        String sing = "中";
        System.out.println(new String(sing.getBytes(Charset.forName("gb2312"))));
        //gbk gb2312 2个字节
        // utf-8 3个字节
        // utf8mb4 4个字节 uncode32
        System.out.println(sing.codePointAt(0));

        System.out.println("abcabcabcabc".indexOf("ab",6));

    }

}
